/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GameClass;

import Game.ShootBalloon;
import javax.microedition.lcdui.*;

/**
 *
 * @author DELL
 */
public class SettingScreen extends Canvas{
    
    private ShootBalloon ownmidlet;
   
    private  Image imutable = null;
    private Image mutableLevel = null;
    private Image mutableSound = null;
    private Image easy = null;
    private Image normal = null;
    private Image hard = null;
    private Image soundOn = null;
    private int index[][] = new int[2][2];
    private int currentY = 0;
    
    private static final int MAX_INDEX = 2;
    public SettingScreen(ShootBalloon midlet)
    {        
        //connect with midlet
        ownmidlet = midlet;
        this.setFullScreenMode(true);
        try{
            imutable = Image.createImage("/resource/screen/SettingsScreen.png");
            easy = Image.createImage("/resource/screen/SettingsScreenEasy.png");
            normal = Image.createImage("/resource/screen/SettingsScreenNormal.png");
            hard = Image.createImage("/resource/screen/SettingsScreenHard.png");
            soundOn = Image.createImage("/resource/screen/SettingsScreenSoundOn.png");
            index[0][1] = 2;
            index[1][1] = 1;
        }
        catch(Exception e)
        {
            
        }
    }
    Graphics g = null;
    public void paint(Graphics g){
        //update image
        this.g = g;
        if(currentY == 0){
            switch(index[0][0]){
                case 0:
                    mutableLevel = easy;
                    break;
                case 1:
                    mutableLevel = normal;
                    break;
                case 2:
                    mutableLevel = hard;
                    break;
            }
            ownmidlet.setLevel(index[0][0]);
        }
        if(currentY == 1){
            switch(index[1][0]){
                case 0:
                    mutableSound = null;
                    break;
                case 1:
                    mutableSound = soundOn;
                    break;
            }
            ownmidlet.setSound(index[1][0]==1);
        }
        g.drawImage(imutable, 0, 0, 0);
        if(mutableLevel!=null){
           g.drawImage(mutableLevel,0,0,0);
        }
        if(mutableSound!=null){
           g.drawImage(mutableSound,0,0,0);
        }
      
    }
    
    public void keyPressed(int keyCode){
        int code = getGameAction(keyCode);
        if(code == UP){
            currentY--;
            if(currentY<0)
                currentY = 1;
        }
        if(code == DOWN){
            currentY++;
            if(currentY>1)
                currentY = 0;
        }
        if(code == LEFT){
            index[currentY][0]--;
            if(index[currentY][0]<0){
                index[currentY][0] = index[currentY][1];
            }                    
        }
        
        if(code == RIGHT){          
            index[currentY][0]++;
            if(index[currentY][0]>index[currentY][1]){
                index[currentY][0] = 0;
            }             
        }
        if(code == KEY_POUND){
             ownmidlet.setCurrent(ownmidlet.getMainMenuScreen());
        }
        repaint();
        
    }
    
    public void pointerPressed(int x,int y){
       
        if(x<getWidth() && x>getWidth()-100
                && y<getHeight() && y>getHeight()-100){
            ownmidlet.setCurrent(ownmidlet.getMainMenuScreen());
        }
    }
    
    /*
    public void commandAction(Command c, Displayable d)
    {
        if(c == Back)
        {
            //code here
            //go to main menu
            ownmidlet.setCurrent(ownmidlet.getMainMenuScreen());
        }
        else
        {
            //code here
            //go back
            int levelidx = Level.getSelectedIndex();
            int soundidx = Sound.getSelectedIndex();
            ownmidlet.setLevel(levelidx);
            boolean t = soundidx == 0?true:false;
            ownmidlet.setSound(t);
            ownmidlet.setCurrent(ownmidlet.getMainMenuScreen());
        }
    }
     * 
     */
    
    
}
